package com.ruoyi.studyroom.bpm.controller;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.studyroom.bpm.domain.vo.BpmProductionNoticeVo;
import com.ruoyi.studyroom.bpm.domain.bo.BpmProductionNoticeBo;
import com.ruoyi.studyroom.bpm.service.IBpmProductionNoticeService;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiOperation;

/**
 * 生产通知单Controller
 *
 * @author hubo_dxy
 * @date 2025-07-07
 */
@Validated
@Api(value = "生产通知单控制器", tags = {"生产通知单管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/studyroom/productionNotice")
public class BpmProductionNoticeController extends BaseController {

    private final IBpmProductionNoticeService iBpmProductionNoticeService;

    /**
     * 查询生产通知单列表
     */
    @ApiOperation("查询生产通知单列表")
    @SaCheckPermission("studyroom:productionNotice:list")
    @GetMapping("/list")
    public TableDataInfo<BpmProductionNoticeVo> list(@Validated(QueryGroup.class) BpmProductionNoticeBo bo, PageQuery pageQuery) {
        return iBpmProductionNoticeService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出生产通知单列表
     */
    @ApiOperation("导出生产通知单列表")
    @SaCheckPermission("studyroom:productionNotice:export")
    @Log(title = "生产通知单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(@Validated BpmProductionNoticeBo bo, HttpServletResponse response) {
        List<BpmProductionNoticeVo> list = iBpmProductionNoticeService.queryList(bo);
        ExcelUtil.exportExcel(list, "生产通知单", BpmProductionNoticeVo.class, response);
    }

    /**
     * 获取生产通知单详细信息
     */
    @ApiOperation("获取生产通知单详细信息")
    @SaCheckPermission("studyroom:productionNotice:query")
    @GetMapping("/{id}")
    public R<BpmProductionNoticeVo> getInfo(@ApiParam("主键")
                                                  @NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return R.ok(iBpmProductionNoticeService.queryById(id));
    }

    /**
     * 新增生产通知单
     */
    @ApiOperation("新增生产通知单")
    @SaCheckPermission("studyroom:productionNotice:add")
    @Log(title = "生产通知单", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody BpmProductionNoticeBo bo) {
        return toAjax(iBpmProductionNoticeService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改生产通知单
     */
    @ApiOperation("修改生产通知单")
    @SaCheckPermission("studyroom:productionNotice:edit")
    @Log(title = "生产通知单", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody BpmProductionNoticeBo bo) {
        return toAjax(iBpmProductionNoticeService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除生产通知单
     */
    @ApiOperation("删除生产通知单")
    @SaCheckPermission("studyroom:productionNotice:remove")
    @Log(title = "生产通知单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@ApiParam("主键串")
                                       @NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iBpmProductionNoticeService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
